<!DOCTYPE html>
<html lang="en">
<head>
    <title>后台管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 导入easyui的资源文件 -->
    <script type="text/javascript" src="/static/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/easyui/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/easyui/themes/icon.css">
    <link id="themeLink" rel="stylesheet" type="text/css" href="/static/easyui/themes/default/easyui.css">

    <script type="text/javascript">
        $(function(){
            // //打开编辑窗口
            $("#addBtn").click(function(){
                //清空表单数据
                $("#editForm").form("clear");
                $("#win").window("open");
                $("#win").window("center");
            });
            //保存数据
            $("#saveBtn").click(function(){
                $("#editForm").form("submit",{
                    //url: 提交到后台的地址
                    url:"saveExamQuestions",
                    //onSubmit: 表单提交前的回调函数，true：提交表单   false：不提交表单
                    onSubmit:function(){
                        //判断表单的验证是否都通过了
                        return $("#editForm").form("validate");
                    },
                    //success:服务器执行完毕回调函数
                    success:function(data){ //data: 服务器返回的数据，类型字符串类
                        //要求Controller返回的数据格式：
                        //成功：{success:true} 失败:{success:false,msg:错误信息}

                        //把data字符串类型转换对象类型
                        data = eval("("+data+")");
                        if(data.success){
                            //关闭窗口
                            $("#win").window("close");
                            //刷新datagrid
                            $("#list").datagrid("reload");
                            $.messager.alert("提示","保存成功","info");
                        }else{
                            $.messager.alert("提示","保存失败："+data.msg,"error");
                        }
                    }
                });
            });

            // //修改数据
            $("#editBtn").click(function(){
                //判断只能选择一行
                var rows = $("#list").datagrid("getSelections");
                if(rows.length!=1){
                    $.messager.alert("提示","修改操作只能选择一行","warning");
                    return;
                }
                //表单回显
                $("#editForm").form("load","findExamQuestionsById?id="+rows[0].id);
                $("#win").window("open");
                $("#win").window("center");
            });
            // //删除
            $("#deleteBtn").click(function(){
                var rows =$("#list").datagrid("getSelections");
                if(rows.length==0){
                    $.messager.alert("提示","删除操作至少选择一行","warning");
                    return;
                }
                //格式： id=1&id=2&id=3
                $.messager.confirm("提示","确认删除数据吗?",function(value){
                    if(value){
                        var idStr = "";
                        //遍历数据
                        $(rows).each(function(i){
                            idStr+=("id="+rows[i].id+"&");
                        });
                        idStr = idStr.substring(0,idStr.length-1);
                        //传递到后台
                        $.post("deleteLoginUser",idStr,function(data){
                            if(data.success){
                                //刷新datagrid
                                $("#list").datagrid("reload");
                                $.messager.alert("提示","删除成功","info");
                            }else{
                                $.messager.alert("提示","删除失败："+data.msg,"error");
                            }
                        },"json");
                    }
                });
            });

        })
    </script>
</head>
<body>

<!-- 数据表格组件 -->
<!-- datagrid是个建表插件~用法 -->
<table id="list" class="easyui-datagrid" url="ExamQuestion" title="用户管理"  fit="true" border="false"
       fitColumns="true" pagination="true"  singleSelect="true"  rownumbers="true"  toolbar="#tb">
    <thead>
    <tr>
        <th data-options="field:'id',checkbox:true" >编号</th>
        <th data-options="field:'lessonname',width:150">考试科目</th>
        <th data-options="field:'subject',width:150">题目</th>
        <th data-options="field:'type',width:150">类型</th>
        <th data-options="field:'optiona',width:150">选项A</th>
        <th data-options="field:'optionb',width:150">选项B</th>
        <th data-options="field:'optionc',width:150">选项C</th>
        <th data-options="field:'optiond',width:150">选项D</th>
        <th data-options="field:'answer',width:100">答案</th>
    </tr>
    </thead>
</table>
<!-- 工具条 -->
<div id="tb">
    <a id="addBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
    <a id="editBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
    <a id="deleteBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
</div>


<!-- 编辑窗口 -->
<div id="win" class="easyui-window" title="数据编辑" style="width:600px;height:450px"
     data-options="iconCls:'icon-save',modal:true,closed:true">
    <form id="editForm" method="post">
        <!--       提供id隐藏域 -->
           <br/>
        <input type="hidden" name="id">
        <table cellpadding="10px">
            <tr>
                <td>所属科目</td>
                <td><input id="cc2" class="easyui-combobox" name="taotiid"
                           data-options="textField:'lessonname',valueField:'taotiid',
                    editable:false, panelHeight:'auto',url:'TeacherExamLessonlist'"></td>
                <td>
            </tr>
            <tr>
                <td>考试题目</td>
                <td><textarea id="subject" name="subject" cols="20" rows="4"></textarea></td>
                <td>试题类型</td>
                <td>
                    <select id="type" name="type" class="easyui-combobox" data-options=" editable:false,panelHeight:'auto'">
                        <option value="单选">单选</option>
                        <option value="多选">多选</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>选项A</td>
                <td><input id="optiona" class="easyui-validatebox" data-options="required:true" name="optiona"></td>
                <td>选项B</td>
                <td><input id="optionb" class="easyui-validatebox" data-options="required:true" name="optionb"></td>
            </tr>
            <tr>
                <td>选项C</td>
                <td><input id="optionc" class="easyui-validatebox" data-options="required:true" name="optionc"></td>
                <td>选项D</td>
                <td><input id="optiond" class="easyui-validatebox" data-options="required:true" name="optiond"></td>
            </tr>
            <tr>
                <td>正确答案</td>
                <td>
                    A<input type="checkbox" name="answer"  value="A">&nbsp;&nbsp;&nbsp;&nbsp;
                    B<input type="checkbox" name="answer" value="B">&nbsp;&nbsp;&nbsp;&nbsp;
                    C<input type="checkbox" name="answer" value="C">&nbsp;&nbsp;&nbsp;&nbsp;
                    D<input type="checkbox" name="answer" value="D">
                </td>
            </tr>
        </table>
        &nbsp;&nbsp;<a id="saveBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
    </form>
</div>
</body>
</html>
